<?php

namespace App\Crontab;

use App\Model\Mysql\OnlineOrderModel;
use App\Service\OrderService;
use EasySwoole\EasySwoole\Crontab\AbstractCronTask;
use EasySwoole\EasySwoole\Task\TaskManager;

class OrderSubmit extends AbstractCronTask
{

    public static function getRule(): string
    {
        return '*/1 * * * *';
    }

    public static function getTaskName(): string
    {
        return 'orderSubmit';
    }


    function run(int $taskId, int $workerIndex)
    {
        $order = OnlineOrderModel::getList(['order_status' => 12], ['id', 'create_time']);

        foreach ($order as $value) {
            if (time() - $value['create_time'] > 180) {
                OnlineOrderModel::editData(['order_status' => 30], ['id' => $value['id']]);
            }
        }
        $order = OnlineOrderModel::getList(['order_status' => 21], ['id', 'create_time']);
        foreach ($order as $value) {
            if (time() - $value['create_time'] > 180) {
                OnlineOrderModel::editData(['order_status' => 30], ['id' => $value['id']]);
            }
        }
    }

    function onException(\Throwable $throwable, int $taskId, int $workerIndex)
    {
        echo $throwable->getMessage();
    }
}
